package z_app_lotto2;

import java.awt.Rectangle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

public class InterWindowAdapter {
	private Rectangle rect;
	private String fileName;
	
	
	
	public InterWindowAdapter(String fileName){
		this.fileName = fileName;
	}
	
	
	public Rectangle read() {
		FileInputStream fis = null;
		ObjectInputStream ois = null;
		
		try{
			File f = new File(fileName);
			if(f.exists()){
				fis = new FileInputStream(new File(fileName));
				ois = new ObjectInputStream(fis);
				rect = (Rectangle)ois.readObject();
			}else{
				rect = new Rectangle(50,50,400,400);
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			try{
				ois.close();
				fis.close();
			}catch(Exception ex2){}

			return rect;
		}
	}

	public void save(Rectangle rect) {
		FileOutputStream fos = null;
		ObjectOutputStream oos = null;
		try{
			fos = new FileOutputStream(fileName);
			oos = new ObjectOutputStream(fos);
			oos.writeObject(rect);
			oos.flush();
			
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			try{
				oos.close();
				fos.close();
			}catch(Exception ex2){}
		}

	}


	public Rectangle getRect() {
		return rect;
	}


	public void setRect(Rectangle rect) {
		this.rect = rect;
	}
	
	
}
